﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Visitor;

namespace ASTClass
{
    class StringAST : TerminalAST
    {
        public StringAST() : base() { name = "String"; }
        public StringAST(AST parent) : base(parent) { name = "String"; }

        public override AST Clone()
        {
            StringAST ast = new StringAST();
            ast.operators = operators;
            foreach (AST c in children)
                ast.children.Add(c.Clone());

            return ast;
        }

        #region Visitor pattern

        public override void Accept(IVisitor visitor)
        {
            visitor.Visit(this);
        }

        #endregion Visitor pattern

        public override void CodeGen(Taste.SymbolTable symTab, Taste.CodeFileGen cfg)
        {
            cfg.AddCommand("li", "$v0, 4");
            cfg.AddCommand("la", "$a0, " + this.UniqueName);
            cfg.AddCommand("syscall", string.Empty);
            cfg.AddCommand("subu", "$sp, $sp, 4");

            cfg.AddDataConst(this.UniqueName, Taste.CodeFileGen.DataType.ASCIIZ, this.Value);
        }
    }
}
